home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-12-29 | 3.8 KB | 148 lines | [TEXT/CWIE] |
- /*****************************************************************************
-
- LDimmableView.cp
- Written by Rick Eames
- ©1994 Natural Intelligence, Inc. && Rick Eames
-
- This class exists for one purpose only: to gray out a view that has
- been disabled. This includes graying out all of the subviews within
- that view. To accomplish this, LDimmableView orders all of the sub-
- views and attachments to draw themselves, checks to see if the view
- is in a disabled state and grays out the view if it is.
-
- The code also does the right thing if running under color.
-
- You have permission to use this class in any application you develop
- as long as you credit both Rick Eames and Natural Intelligence, Inc. in
- your credits.
-
- *****************************************************************************/
-
- #include "LDimmableView.h"
- #include <LView.h>
- #include <LList.h>
- #include <LListIterator.h>
- #include <LStream.h>
- #include <PP_Messages.h>
- #include <UDrawingState.h>
- #include "U3DAttachments.h"
- #include <UDrawingUtils.h>
-
- /*****************************************************************************
- LDimmableView
-
- Constructor from a stream. Does nothing but call the LView constructor.
- *****************************************************************************/
-
- LDimmableView::LDimmableView(LStream *inStream)
- : LView(inStream)
- {
-
- }
-
- /*****************************************************************************
- CreateDimmableViewStream
-
- Returns a new LDimmableView.
- *****************************************************************************/
-
- LDimmableView *
- LDimmableView::CreateDimmableViewStream(LStream *inStream)
- {
- return (new LDimmableView(inStream));
- }
-
- /*****************************************************************************
- DimInColor
-
- Using opCodes and PenModes, gray out a view.
- *****************************************************************************/
-
- void LDimmableView::DimInColor(Rect *inDrawRect, unsigned short tint, Boolean makeLighter)
- {
- StColorState savedColorInfo;
- StColorPenState savedPenState;
- RGBColor newRGBColor, newOpColor;
- short arithPenMode;
-
- newOpColor.red = newOpColor.blue = newOpColor.green = tint;
-
- arithPenMode = blend;
-
- if (makeLighter)
- newRGBColor.red = newRGBColor.blue = newRGBColor.green = 0xFFFF;
- else
- newRGBColor.red = newRGBColor.blue = newRGBColor.green = 0x0000;
-
- OpColor(&newOpColor);
- RGBForeColor(&newRGBColor);
- PenMode(arithPenMode);
- PenPat(&qd.black);
- PaintRect(inDrawRect);
- }
-
- /*****************************************************************************
- Draw
-
- Simple draw method. If running under color it calls the DimInColor
- method. Otherwise it dims in a standard black and white method.
- *****************************************************************************/
-
- void LDimmableView::Draw(RgnHandle inSuperDrawRgnH)
- {
- if (IsVisible() && FocusDraw())
- {
- RectRgn(mUpdateRgnH, &mRevealedRect);
- if (inSuperDrawRgnH != nil)
- {
- SectRgn(inSuperDrawRgnH, mUpdateRgnH, mUpdateRgnH);
- }
-
- if (!EmptyRgn(mUpdateRgnH))
- {
- // Some portion needs to be drawn
- Rect frame;
- CalcLocalFrameRect(frame);
- if (ExecuteAttachments(msg_DrawOrPrint, &frame))
- {
- DrawSelf();
- }
- LListIterator iterator(mSubPanes, iterate_FromStart);
- LPane *theSub;
- while (iterator.Next(&theSub))
- {
- theSub->Draw(mUpdateRgnH);
- }
-
- FocusDraw();
-
- if (mEnabled != triState_On)
- {
- StDeviceLoop theLoop(frame);
- Int16 depth;
- Rect frame;
-
- CalcLocalFrameRect(frame);
-
- while (theLoop.NextDepth(depth))
- {
- if (depth >= 4)
- {
- DimInColor(&frame, 0x7530, true);
- }
- else
- {
- StColorPenState savedPenState;
-
- PenMode( patBic );
- PenPat(&qd.gray);
- PaintRect(&frame);
- }
- }
- }
-
- }
- SetEmptyRgn(mUpdateRgnH);
- }
-
- }